//
//  MessageCell.m
//  Tunnel
//
//  Created by wbb on 2025/6/2.
//


#import "MessageCell.h"

@interface MessageCell()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) UILabel *detailLabel;
@end

@implementation MessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        self.backgroundColor = [UIColor clearColor];
        [self initUI];
    }
    return  self;
}
- (void)initUI {
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(8);
        make.bottom.offset(-7);
        make.right.offset(-12);
        make.left.offset(12);

    }];
    
    // 创建图片视图
    self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
    self.imgView.contentMode = UIViewContentModeScaleAspectFit;
    self.imgView.image = [UIImage imageNamed:@"message_jkgj"];
    [bgView addSubview:self.imgView];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
    }];
    
    // 创建标题标签
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    self.titleLabel.textColor = main_text_color;
    [bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(4);
        make.centerY.mas_equalTo(self.imgView.mas_centerY);
        make.top.offset(5);
    }];
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor colorWithRed:254/255.0 green:34/255.0 blue:34/255.0 alpha:1];
    view.cornerRadius = 2.5;
    [bgView addSubview:view];
    self.redView = view;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-8);
        make.top.offset(8);
        make.height.width.offset(5);
    }];
    
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.textColor = main_light_text_color_9;
    [bgView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(10);
        make.left.mas_equalTo(10);
        make.right.offset(-10);
    }];
    
    
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.font = [UIFont systemFontOfSize:14];
    self.timeLabel.textColor = main_light_text_color_9;
    [bgView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.offset(-10);
        make.height.offset(16);
    }];
    
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.font = [UIFont systemFontOfSize:14];
    detailLabel.text =@"查看详情";
    detailLabel.textColor = main_light_text_color_9;
    [bgView addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.bottom.offset(-10);
    }];
    self.detailLabel = detailLabel;
    
    //    UIButton *detailBtn = [UIButton buttonWithTitle:@"查看详情" titleColor:main_light_text_color_9 font:[UIFont systemFontOfSize:14] target:self action:@selector(goDetail)];
    //    [bgView addSubview:detailBtn];
    //    [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.right.offset(-10);
    //        make.bottom.offset(-10);
    //    }];
    
    UILabel *lineLab = [UILabel new];
    lineLab.backgroundColor = main_line_color;
    [bgView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(10);
        make.bottom.equalTo(self.timeLabel.mas_top).offset(-10);
        make.height.offset(1);
    }];
    
    
    bgView.layer.shadowColor = [UIColor colorWithRed:156/255.0 green:175/255.0 blue:210/255.0 alpha:0.2].CGColor;
    bgView.layer.shadowOffset = CGSizeMake(0,4);
    bgView.layer.shadowOpacity = 1;
    bgView.layer.shadowRadius = 8;
    bgView.layer.cornerRadius = 7;
}

- (void)goDetail {
    if(self.goDetailBlock) {
        self.goDetailBlock();
    }
}
- (void)setCornerForIndexPath:(NSIndexPath *)indexPath totalRows:(NSInteger)totalRows dataSource:(NSArray *)dataArray {
    
    NSDictionary *dic = dataArray[indexPath.row];
    
    self.imgView.image = [UIImage imageNamed:dic[@"imgName"]];
    self.titleLabel.text = dic[@"title"];
}

- (void)setDataDic:(NSDictionary *)dataDic{
    
    self.imgView.image = [UIImage imageNamed:dataDic[@"imgName"]];
    self.titleLabel.text = dataDic[@"title"];
    self.contentLabel.text = dataDic[@"content"];
    self.timeLabel.text = dataDic[@"time"];
}
-(void)setModel:(MessageModel *)model{
    _model = model;
    self.titleLabel.text = model.bizType;
    self.contentLabel.text = model.nr;
    self.timeLabel.text = model.created_time;
    self.redView.hidden = model.isRead;
    self.detailLabel.text =@"查看详情";
    if([model.msgType isEqualToString:@"EMERGENCECREATION"]){
        //应急事件
        self.imgView.image = [UIImage imageNamed:@"message_yjsj"];

    }else if ([model.msgType isEqualToString:@"ENERGYUSEEXCEPT"]){
        //能耗告警
        self.imgView.image = [UIImage imageNamed:@"message_nhgj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"DEVICE_ALERTS"]){
        //预测告警
        self.imgView.image = [UIImage imageNamed:@"message_ycgj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"INSIDE_EQUIPMENT_MONITORING_ALARMING"]){
        //内场设备告警
        self.imgView.image = [UIImage imageNamed:@"message_jkgj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"HIGH_PASSENGER_FLOW_WARNING"]||
              [model.msgType isEqualToString:@"TRAFFIC_PERCEPTION_MONITORING"]||
              [model.msgType isEqualToString:@"THE_TRAFFIC_FLOW_AT_THE_ENTRANCE_AND_EXIT_IS_ABNORMAL"]||
              [model.msgType isEqualToString:@"THE_RATIO_OF_PASSENGERS_TO_GOODS_IS_ABNORMAL"]||
              [model.msgType isEqualToString:@"ANOMALOUS_VEHICLES"]
             ){
        //大客流预警
        self.imgView.image = [UIImage imageNamed:@"message_clyj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"MANUALLY_FILL_IN_THE_ALARM"]){
        //人工填报告警
        self.imgView.image = [UIImage imageNamed:@"message_gzgj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"SPARESLOW"]){
        //备品备件
        self.imgView.image = [UIImage imageNamed:@"message_bpbj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"SPARESLOW"]){
        //备品备件
        self.imgView.image = [UIImage imageNamed:@"message_bpbj"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"WORKORDERDCL"] ||
              [model.msgType isEqualToString:@"WORKORDERASSIGN"]
              ){
        //工单提醒
        self.imgView.image = [UIImage imageNamed:@"message_gdtx"];
        self.detailLabel.text = @"清除已读";

    }else if ([model.msgType isEqualToString:@"PLC_FAULT_ALARMS"]) {
        //故障告警
        self.imgView.image = [UIImage imageNamed:@"message_gzgj"];

    }else if ([model.msgType isEqualToString:@"THRESHOLD_MONITORING_ALARMS"]) {
        // 监控告警
        self.imgView.image = [UIImage imageNamed:@"message_jkgj"];

    }else if ([model.msgType isEqualToString:@"THE_DEVICE_IS_OFFLINE"]) {
        self.imgView.image = [UIImage imageNamed:@"message_yxjc"];
    }else if ([model.msgType isEqualToString:@"SECURITYREVIEW"]) {
        self.imgView.image = [UIImage imageNamed:@"message_aqjc"];
    }else if ([model.msgType isEqualToString:@"NON_MOTORIZED_VEHICLE_BREAK_IN"] || [model.msgType isEqualToString:@"PEDESTRIAN_TRESPASSING"] || [model.msgType isEqualToString:@"SCATTERED_OBJECTS"] || [model.msgType isEqualToString:@"WORK_CAR"]) {
        
        //视频监控
        self.imgView.image = [UIImage imageNamed:@"message_ai"];

    }else if ([model.msgType isEqualToString:@"MULTI_VEHICLE_ACCIDENTS"] || [model.msgType isEqualToString:@"BICYCLE_PARKING"] || [model.msgType isEqualToString:@"RETROGRADE"] || [model.msgType isEqualToString:@"LANE_CHANGES_IN_VIOLATION_OF_REGULATIONS"] || [model.msgType isEqualToString:@"CRIMPING"] || [model.msgType isEqualToString:@"OCCUPY_A_DEDICATED_LANE"] || [model.msgType isEqualToString:@"TRAFFIC_CONGESTION"] ){
        
        //视频监控
        self.imgView.image = [UIImage imageNamed:@"message_ai"];

    }else if ([model.msgType isEqualToString:@"FOCUS_ON_VEHICLES"] ){// 超高
        //视频监控
        self.imgView.image = [UIImage imageNamed:@"message_ai"];
    }

    
    
    
    
    
}
@end

